<?php
declare (strict_types = 1);
namespace app\admin\model\data;

/**
 * 访问记录统计数据
 */
class VisitTotal extends DataModel
{
    /**
     * 表名
     * @var string
     */
    protected $name = 'website_visit_total';

    // 定义全局的查询范围
    protected $globalScope = ['mhm'];
    /**
     * 获取课程类型的资源
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-07-27
     * @return   [type]                         [description]
     */
    public static function getCourseResourceTypes()
    {
        return [
            'live',
            'live_small',
            'video',
            'classes',
        ];
    }

    /**
     * pv
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-07-16
     * @param    array 时间区间
     * @return   [type]                                   [description]
     */
    public static function getPvByTimespan(array $timespan)
    {
        return (int) VisitTotal::whereBetween('visit_time', $timespan)->sum('pv');
    }

    /**
     * uv
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-07-16
     * @param    array 时间区间
     * @return   [type]                                   [description]
     */
    public static function getUvByTimespan(array $timespan)
    {
        return VisitTotal::whereBetween('visit_time', $timespan)->value('count(DISTINCT ip)');
    }
}
